#!/usr/bin/env python
# encoding: utf-8
'''
@author: cunyu
@contact: 1372307989@qq.com
@software: Pycharm
@file: ciyun_demo.py
@time: 2018/1/27 16:19
@desc:
'''
from wordcloud import WordCloud
import numpy
import PIL.Image as Img
import jieba


def jieba_text(text):
    jieba_t = jieba.cut(text)
    jieba_list = " ".join(jieba_t)
    return jieba_list


def ciyun():
    text_path = input("请输入要分析的文本完整路径：")
    with open(text_path, "r") as fp:
        text = fp.read()
        text = jieba_text(text)
        img_path = input("请输入要作为背景的图片完整路径：")
        mask_pic = numpy.array(Img.open(img_path))
        wordcloud = WordCloud(font_path="FZLTXIHK.TTF", mask=mask_pic).generate(text)
        img = wordcloud.to_image()
        img.show()


ciyun()
